
import productTopItemStyle from "data-text:@Styles/productTopItemStyle.scss"
import {
  Button,

} from "@bytedance/mona-ui"
import type {
  PlasmoCSConfig,
  PlasmoGetInlineAnchor,
  PlasmoGetStyle,
  PlasmoMountShadowHost
} from "plasmo"
import React, { useState } from "react"
import { Provider } from "react-redux"

import { PersistGate } from "@plasmohq/redux-persist/integration/react"

import { persistor, store, useAppDispatch, useAppSelector } from "~store"


// setactivityToolType

export const getStyle: PlasmoGetStyle = () => {
  const style = document.createElement("style")
  style.textContent = productTopItemStyle
  return style
}

export const config: PlasmoCSConfig = {
  matches: ["https://fxg.jinritemai.com/*"]
}

export const getInlineAnchor: PlasmoGetInlineAnchor = () => {
  return document.querySelector('[class*="index_batch"]') as HTMLElement
}
// export const getInlineAnchorList: any = async () => {
//   const urls = location.pathname === "/ffa/morder/order/list"
//   if (!urls) return
//   const detailList = document.querySelectorAll('[style*="display: flex; flex-direction: column; align-items: center"]')
//   return detailList

// }
export const mountShadowHost: PlasmoMountShadowHost = ({
  shadowHost,
  anchor,
  mountState
}) => {
  // const addchi = document.querySelector('[class*="index_batch"]')
  // addchi && anchor?.element?.insertBefore(shadowHost, addchi.nextSibling)
  // anchor?.element.insertBefore(shadowHost, anchor.element.children[0])
  anchor?.element.appendChild(shadowHost)

  mountState?.observer?.disconnect()
}

// export const getShadowHostId = () => "product-top-item-id"

const TaberTopBut = () => {


  return (
    <Button style={{
      marginLeft: 10
    }} onClick={() => {
      window.open('http://dym.11daifa.com/')
    }}><img src="https://dym.11daifa.com/favicon.ico" style={{
      width: 16,
      height: 16,
      marginRight: 5,
      marginBottom: 3
    }} />
      礼品网</Button>
  )
}

const PlasmoInline = () => {
  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <TaberTopBut />
      </PersistGate>
    </Provider>
  )
}

export default PlasmoInline
